package com.example.gerenciadorestudo;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Avaliacoes extends Activity {
	private ListView listaAvaliacoes;
	private ArrayAdapter<String> avaliacoes;
	private ArrayList<Avaliacao> listaNomeAvaliacoes;
	private static String[] nome_avaliacoes;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_avaliacoes);
		listaAvaliacoes = (ListView)findViewById(R.id.listaAvaliacoes);
		
		listaNomeAvaliacoes = MainActivity.banco.listarAvaliacoes();
		
		
		listaAvaliacoes.setAdapter(new AvaliacaoAdapter(this, listaNomeAvaliacoes));
		
		listaAvaliacoes.setOnItemClickListener( new OnItemClickListener() {
		    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		    	Avaliacao resultado = listaNomeAvaliacoes.get(position);
		        Log.d("hehehe", resultado.getDescricao());
		        Intent telaVisualizaAv = new Intent(Avaliacoes.this,VisualizaAvaliacao.class);
				telaVisualizaAv.putExtra("descricao", resultado.getDescricao());
				startActivity(telaVisualizaAv);
		    }
		});
		
	}
		

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_avaliacoes, menu);
		return true;
	}
	
	public void entrarNovaAvaliacao(View v){
		Intent i = new Intent(this, NovaAvaliacao.class);
		startActivity(i);
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		listaAvaliacoes = (ListView)findViewById(R.id.listaAvaliacoes);
		
		listaNomeAvaliacoes = MainActivity.banco.listarAvaliacoes();
		
		
		listaAvaliacoes.setAdapter(new AvaliacaoAdapter(this, listaNomeAvaliacoes));
	}

}
